﻿namespace KinonekoSoftware.CodariaDB.Core
{
    public sealed class ImageSystem : _File
    {
        public ImageSystem() : base("Images", ResourceType.Image)
        {

        }
        
        
        protected override Occupation OnCreate(string id) => new Occupation
        {
            Id       = id,
            FileName = id,
            Usage    = true,
            Type     = ResourceType.Image,
        };

        public Stream OpenThumbnail(string id)
        {
            var fileName = Path.Combine(Folder, string.Format(ThumbnailFilePattern, id));
            var stream   = new FileStream(fileName, FileMode.Open);
            return stream;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="buffer"></param>
        public async Task WriteThumbnailAsync(string id, byte[] buffer)
        {
            var fileName = Path.Combine(Folder, string.Format(ThumbnailFilePattern, id));

            //
            //
            await File.WriteAllBytesAsync(fileName, buffer);
        }

        public override string EngineID => EngineNames.FileDataSet_Image;
    }

}